package com.ruoyi.manage.strategy.Impl;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.manage.DTO.ChargingDTO;
import com.ruoyi.manage.strategy.BillingPolicies;
import org.omg.CORBA.SystemException;

import java.math.BigDecimal;

/**
 * @Title:
 * @BelongProjecet online-car-hailing
 * @BelongPackage com.ruoyi.manage.strategy.Impl
 * @Description: 超时计费策略
 * @Copyright
 * @Author: 马朝斌
 * @Date: 2024-07-03 15:25
 * @Version V1.0
 */
public class TimeOutBillingPolicy implements BillingPolicies {

    /**
    * @Author 马朝斌
    * @Description //TODO 订单的超时计费策略
    * @Date 16:24 2024/7/3
    * @Param
     * @param chargingDTO
    * @return com.ruoyi.common.core.web.domain.AjaxResult
    */

    @Override
    public AjaxResult billingPolicies(ChargingDTO chargingDTO) throws SystemException {
        //获取订单的总时间
        Double orderTime = chargingDTO.getOrderTime();
        //获取起步时间
        Double startTime = chargingDTO.getStartingTime();
        //获取超时的时长
        double outTime = orderTime - startTime;
        //获取超时每分钟的价格
        BigDecimal outOrderTimePrice = chargingDTO.getOutOrderTimeUnitPrice();
        //计算超时总费用
        chargingDTO.setOutOfTimeTotalPrice(outOrderTimePrice.multiply(new BigDecimal(outTime)));
        //计算总费用 订单价格 = 超时总费用 + 起步价格
        chargingDTO.setOrderPrice(chargingDTO.getOrderPrice()
                .add(chargingDTO.getOutOfTimeTotalPrice())
                .add(chargingDTO.getStartingPrice()));
        return AjaxResult.success(chargingDTO);
    }

}
